/*
 * UnitAnimalMoving.cpp
 *
 *  Created on: 2013-1-19
 *      Author: heqiu
 */

#include "UnitAnimalMoving.h"

namespace guud {

UnitAnimalMoving::UnitAnimalMoving() {
	m_pUnitAnimalPosition = NULL;
}
void UnitAnimalMoving::init(UnitAnimalPosition * pUnitAnimalPosition) {
	m_pUnitAnimalPosition = pUnitAnimalPosition;
}
void UnitAnimalMoving::addAnimal(UnitAnimal & stUnitAnimal) {
	if (m_mapUnitAnimal.find(stUnitAnimal.m_iId) == m_mapUnitAnimal.end()) {
		m_mapUnitAnimal[stUnitAnimal.m_iId] = &stUnitAnimal;
	}
}
void UnitAnimalMoving::delAnimal(uint32_t uiId) {
	m_mapUnitAnimal.erase(uiId);
}
void UnitAnimalMoving::moving() {
	uint32_t uiTime = GuudTime::getMsec();
	for (std::map<uint32_t, UnitAnimal *>::iterator it =
			m_mapUnitAnimal.begin(); it != m_mapUnitAnimal.end(); it++) {
		int iX;
		int iY;
		it->second->moving(uiTime, iX, iY);
		if (m_pUnitAnimalPosition != NULL) {
			m_pUnitAnimalPosition->addAnimal(it->first, iX, iY);
		}
	}
}
}
